home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: undergrad.math.uwaterloo.ca!sckettle
- From: sckettle@undergrad.math.uwaterloo.ca (Steve Kettle)
- Subject: Re: How to generate all the combinations of n numbers?
- Sender: news@undergrad.math.uwaterloo.ca (news spool owner)
- Message-ID: <DnICrA.Dox@undergrad.math.uwaterloo.ca>
- Date: Wed, 28 Feb 1996 22:49:58 GMT
- References: <4giuc9$pq@news.cis.okstate.edu>
- Nntp-Posting-Host: noether.math.uwaterloo.ca
- Organization: University of Waterloo
-
- In article <4giuc9$pq@news.cis.okstate.edu>,
- Madhav Kakani <kakani@osuunx.ucc.okstate.edu> wrote:
- >Hello everybody,
- > I am having problems in writing a c/c++ program which
- >generates all possible combinations of n given numbers.
- >For example, if an array x has some numbers
- >
- >int x[] = {1,2,3};
- >
- >the program should generate the following output:
- >1
- >2
- >3
- >12
- >13
- >23
- >123
- >
- >Thanks in advance,
- > -madhav
- >
-
- I won't give you the answer but recursion is the way to go. Eg. if you
- know the combinations of n-1 numbers then what can you say about the
- combinations of n numbers.
-
- This is for distinct numbers only - I allowed to repeat the same number
- more than once it prob. gets hairy.
- --
-